package com.javatest.spi;

import sun.misc.Service;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @date 2020-08-06 上午9:47
 */
public class App {
    public static void main(String[] args) {
        ServiceLoader<TestInterface> load = ServiceLoader.load(TestInterface.class);
        Iterator<TestInterface> iterator = load.iterator();
        while (iterator.hasNext()) {
            TestInterface next = iterator.next();
            next.test();
        }
        System.out.println("----------------------------------");
        // 下面这种方式也可以
        Iterator<TestInterface> providers = Service.providers(TestInterface.class);
        while (providers.hasNext()) {
            TestInterface next = providers.next();
            next.test();
        }
    }
}
